package com.zq.assistant.func.ioc.finder.field;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangqiang on 17-7-11.
 */

public class BaseFieldFinder implements InjectFieldFinder {

    private Class<?> abortClass;

    public BaseFieldFinder(Class<?> abortClass) {
        this.abortClass = abortClass;
    }

    @Override
    public List<Field> findInjectFields(Class targetClass, Class<? extends Annotation> annotationClass) {

        List<Field> fieldList = new ArrayList<>();

        while(!abortClass.equals(targetClass)){

            Field[] fields = targetClass.getDeclaredFields();
            for (Field field:
                    fields) {

                if(field.getAnnotation(annotationClass) != null){
                    fieldList.add(field);
                }
            }
            targetClass = targetClass.getSuperclass();
        }
        return fieldList;
    }
}
